<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" type="text/css" href="css/common.css"/>
	<link rel="stylesheet" type="text/css" href="css/article_list.css"/>
</head>
<body>

<form action="" method="post" class="search_box">
	<span>推广人员：<input type="text" id="name" name="name"/></span>

	<button type="button" class="sub">搜索</button>
</form>
<div id="list_content">

</div>

<div class="tcdPageCode"></div>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script src="js/jquery.page.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
<script>
			jQuery.browser = {};
			(function() {
				jQuery.browser.msie = false;
				jQuery.browser.version = 0;
				if(navigator.userAgent.match(/MSIE ([0-9]+)./)) {
					jQuery.browser.msie = true;
					jQuery.browser.version = RegExp.$1;
				}
			})();

			var params = {
				name:'', //姓名
				limit: 10, //记录数
				offset: 1 //页码
			};
			$(document).ready(function() {

				search();//搜索

					//绑定搜索事件
					$(".sub").click(function() {
						params.name = $("#name").val();
						search();
					});

			});
			//删除方法
			function del(id) {
			  $.cookie("codeId",id, { expires: 1 });
				 var text = "生成二维码";
					$(window.parent.$(".acrossTab li").each(function() {
							if ($(this).children('span').text() == text) {
									$(window.parent.$("aside").attr('data-tip', 1));
									$(this).click();
							} else {
									$(window.parent.$("aside li").each(function() {
											if ($(this).text() == text) {
													$(this).click();
											}
									}));
							}
					}));



			}
			//查询方法
			function search() {

				$.ajax({
					url: '/code/list',
					type: 'get',
					data: params,
					dataType: "json",
					success: function(data) {
						var headTable = "<table border='0' cellspacing='0' cellpadding='0'><tr><th>ID</th><th style='text-align: left;'>推广人员</th>" +
							"<th>二维码</th><th>有效期</th><th>操作</th></tr>";
						var contentHtml = "";
						if(data.rows) {
							var reg = new RegExp(",", "g");
							for(var i = 0; i < data.rows.length; i++) {
								var obj = data.rows[i];
								var index = i + 1;
								var imgHtml = "",indateHtml="";
								if(obj.codePic) {
									imgHtml = "<img class='erweima' src='" + obj.codePic + "'/>";
								} else {
									imgHtml = "二维码生成失败";
								}
								if(obj.indate) {
                  if(obj.indate==""){
                     indateHtml = "无限";
                  }else{
                     indateHtml = obj.indate;
                  }

								} else {
								  indateHtml = "无限";

								}
								contentHtml += "<tr><td>" + obj.id + "</td><td style='text-align: left;'>" + obj.name + "</td>" +
									"<td  >" + imgHtml + "</td>"+	"<td  >" + indateHtml + "</td>"+
									"<td><button id='" + obj.id + "' class='del'>编辑</button></td>	</tr>";
									//<button id='" + obj.id + "' class='del'>编辑</button>
							}
						} else {
							contentHtml = "<tr><td colspan='5'>暂无记录</td></tr>";
						}

						$("#list_content").html(headTable + contentHtml + "</table>");
						$('.erweima').click(function(){
							$(window.parent.$('.zzc').show())
							$(window.parent.$('.box').show())
							$(window.parent.$('.big').attr('src',$(this).attr('src')))
						});
						//绑定删除事件
						$(".del").click(function() {

							var id = $(this).attr("id");
								del(id);

							/*if(confirm("确认删除此信息？")){
									del($(this).attr("id"));
							}*/
						});
						$(".tcdPageCode").createPage({
							pageCount: data.totalPages,
							current: data.page,
							backFn: function(p) {
								//console.log(p);
								params.offset = p;
								search();
							}
						});
					}
				});
			}

			document.onkeydown = function(event){
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if(e && e.keyCode == 116){
					event.preventDefault();

					$(window.parent.$('.showIframe').each(function(){
						if(!$(this).hasClass('hideIframe')){
							$(this).children('iframe').attr('src',$(this).children('iframe').attr('src'))
						}
					}))
				}
			}
		</script>
</body>
</html>
